/*
 *  * Copyright (C) 2021 Huawei Device Co., Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package com.inqbarna.tablefixheaders.samples.slice;

import com.inqbarna.tablefixheaders.samples.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    Button b1, b2, b3;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        b1 = (Button) findComponentById(ResourceTable.Id_simple);
        b2 = (Button) findComponentById(ResourceTable.Id_style);
        b3 = (Button) findComponentById(ResourceTable.Id_family);
        b1.setClickedListener(this);
        b2.setClickedListener(this);
        b3.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ABILITY_NEW_MISSION);
        switch (component.getId()) {
            case ResourceTable.Id_simple:
                present(new SimpleTable(), intent);
                break;
            case ResourceTable.Id_style:
                present(new StyleTable(), intent);
                break;
            case ResourceTable.Id_family:
                present(new FamilyTable(), intent);
                break;
        }

    }
}
